package com.wetsion.securityoauthdemo.rmsclient.common;

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 自定义 accessToken实体
 *
 * @author weixin
 * @version 1.0
 * @CLassName RmsOauthAccessToken
 * @date 2019/3/8 2:48 PM
 */
public class RmsOauthAccessToken {

    private String accessToken;

    private String tokenType = "bearer";

    private Date expiration;

    private String scope;

    private Map<String, Object> additionalInformation = Collections.emptyMap();

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getTokenType() {
        return tokenType;
    }

    public void setTokenType(String tokenType) {
        this.tokenType = tokenType;
    }

    public void setValue(String value) {
        this.accessToken = value;
    }

    /**
     * The token value.
     *
     * @return The token value.
     */
    public String getValue() {
        return accessToken;
    }

    public int getExpiresIn() {
        return expiration != null ? Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L)
                .intValue() : 0;
    }

    protected void setExpiresIn(int delta) {
        setExpiration(new Date(System.currentTimeMillis() + delta));
    }

    public boolean isExpired() {
        return expiration != null && expiration.before(new Date());
    }

    public Date getExpiration() {
        return expiration;
    }

    public void setExpiration(Date expiration) {
        this.expiration = expiration;
    }

    public String getScope() {
        return scope;
    }

    public void setScope(String scope) {
        this.scope = scope;
    }

    public Map<String, Object> getAdditionalInformation() {
        return additionalInformation;
    }

    public void setAdditionalInformation(Map<String, Object> additionalInformation) {
        this.additionalInformation = new LinkedHashMap<String, Object>(additionalInformation);
    }
}
